package cn.lutu.lutu.controller;

import cn.lutu.lutu.response.ResultVO;
import cn.lutu.lutu.security.CustomUserDetails;
import cn.lutu.lutu.service.CartService;
import cn.lutu.lutu.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/**
 * @date 2023-06-03
 * @author luoyinhan
 * */
@Slf4j
@Api(tags = "订单模块")
@RestController
@RequestMapping("/v1/orders/")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    CartService cartService;

    @PostMapping("addOrders")
    @ApiOperation("多条订单添加")
    public ResultVO payProducts(@RequestBody Long id){
        orderService.insertOrder(id);//添加商品订单
        cartService.deleteProduct(id);//删除购物车中的商品
        return ResultVO.ok();
    }

    @GetMapping("selectAll")
    @ApiOperation("所有订单")
    public ResultVO OrderList(@AuthenticationPrincipal CustomUserDetails ud){
        return ResultVO.ok(orderService.orderList(ud.getId()));
    }
}
